package cn.jofei.client.moni;

import cn.jofei.common.config.AppProperties;
import cn.jofei.common.monitor.ServerPortMonitor;
import cn.jofei.common.monitor.msg.DingMsg;
import cn.jofei.common.utils.Utils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * 客户端监控器
 *
 * @author Jofei Bao
 * @version ngbao v1.0.2
 * @date 2022/7/15 16:53
 */
public class InfoMonitor implements Callable<Object> {

//    private static final List<MonitorInfo> MONITOR_INFO_LIST = new ArrayList<>();

//    static {
//        //端口
//
//        //磁盘
//        List<String> diskList = AppProperties.get("monitor.disk", List.class).orElse(new ArrayList());
//        if (Utils.nonNull(diskList)) diskList.forEach(line -> {
//            String[] split = line.split(" ");
//            MonitorInfo info = new MonitorInfo();
//            info.setType(Type.DISK);
//            info.setPath(split[0]);
//            info.setPer(Double.parseDouble(split[1]));
//            info.setServerName(ShellActuator.executeSimple(Commands.SH_GET_IP));
//            MONITOR_INFO_LIST.add(info);
//        });
//        //kafka
//        String kafkaPath = AppProperties.get("monitor.kafka.script-path");
//        Integer backlog = AppProperties.get("monitor.kafka.backlog", Integer.class).orElse(300);
//        String servers = AppProperties.get("monitor.kafka.servers");
//        MonitorInfo info = new MonitorInfo();
//        info.setType(Type.KAFKA);
//        info.setKafkaPath(kafkaPath);
//        info.setServers(servers);
//        info.setBacklog(backlog);
//        info.setServerName("Kafka 消费");
//        MONITOR_INFO_LIST.add(info);
//    }

    @Override
    public Object call() throws Exception {
        int period = AppProperties.get("monitor.period", Integer.class).orElse(60) * 1000;
        return null;
    }

    public static void main(String[] args) {
//        List<String> portList = AppProperties.get("monitor.port", List.class).orElse(new ArrayList());
//        if (Utils.nonNull(portList)) portList.forEach(line -> {
//            String[] split = line.split(" ");
//            String[] serPor = split[0].split(":");
//            new ServerPortMonitor(split[1], serPor[0], Integer.parseInt(serPor[1])).reg();
//        });
        DingMsg.markdown("标题").h4("标题").h5("内容").build().send();
    }
}
